--浮光跃金
local fuguangyuejin = fk.CreateSkill {
    name = "mcdh_fuguangyuejin"
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

fuguangyuejin:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and player.phase == Player.Finish
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local judge = {
            who = player,
            reason = self.name,
            pattern = ".|.|heart",
        }
        room:judge(judge)
        if player:isAlive() then
            if judge.card.suit == Card.Heart then
                local num = 999
                local canchoose = {}
                for _, t in ipairs(room:getOtherPlayers(player)) do
                    local tem = #t:getCardIds(Player.Hand) - #player:getCardIds(Player.Hand)
                    if tem < 0 then
                        tem = -tem
                    end
                    if tem < num then
                        num = tem
                        canchoose = {}
                    end
                    if tem == num then
                        table.insert(canchoose,t)
                    end
                end
                canchoose = table.map(table.filter(canchoose,function (t)
                    return t:isWounded()
                end),Util.IdMapper)
                if #canchoose > 0 then
                    local tos = room:askForChoosePlayers(player,canchoose,1,1,"#mcdh_fuguangyuejin_askplayer",self.name,false)
                    local to = room:getPlayerById(tos[1])
                    room:recover({
                        who = to,
                        num = 1,
                        recoverBy = player,
                        skillName = self.name
                    })
                end
            end
        end
    end
})

Fk:loadTranslationTable{
    ["mcdh_fuguangyuejin"] = "浮光",
    [":mcdh_fuguangyuejin"] = '『浮光跃金』<br>结束阶段，你可以判定，若结果为<font color="red">♥</font>，你令手牌数与你相差最小的一名其他角色回复1点体力。',
    ["#mcdh_weiwulingjun_askcard"] = "威武领军：将一张牌置于牌堆顶",
    ["#mcdh_fuguangyuejin_askplayer"] = "浮光跃金：令一名角色回复1点体力"
}
return fuguangyuejin